package cn.hairui.blog.controller;

import cn.hairui.blog.config.WebLog;
import cn.hairui.blog.constant.PubConstant;
import cn.hairui.blog.model.Music;
import cn.hairui.blog.model.WebInfo;
import cn.hairui.blog.service.MusicService;
import cn.hairui.blog.service.WebInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * <p>
 * <h2>请添加说明
 * </h2>
 * <ol>请添加详细说明
 * </ol>
 *
 * <h2>修改历史
 * </h2>
 * <ol>如有修改，请添加修改历史
 * </ol>
 *
 * </p>
 *
 * @author laoganbu
 * @version V1.0
 * @date 2019/8/1 15:35
 */
@Controller
public class MusicController {

    @Autowired
    private WebInfoService webInfoService;
    @Autowired
    private MusicService musicService;

    @RequestMapping(value = "music")
    @WebLog(description = "欢迎访问音乐馆")
    public String music(String code, Model model) {
        if ("".equals(code) || code == null) {
            model.addAttribute("code", "-1");
        } else {
            model.addAttribute("code", code);
        }

        WebInfo webInfo = webInfoService.find(PubConstant.MY_INFO_ID);
        model.addAttribute("webinfo", webInfo);

        List<Music> musicList = musicService.findByUid(PubConstant.MY_INFO_ID);
        model.addAttribute("musics", musicList);
        //todo 动态获取默认歌单
        model.addAttribute("default_code", "2007653931");
        return "music";
    }
}
